<?php
  require_once("../includes/config.php"); 
  
    $conditions=query("SELECT * FROM conditions WHERE owner_id=?",$_SESSION['user_id']);
  
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
  if($_POST['sub']=="تعديل")
  {
  
  $sql=query("UPDATE conditions SET condition_txt=? WHERE owner_id =?",$_POST['conditions'],$_SESSION['user_id']);
  $_SESSION['success_message'] = "تم التعديل بنجاح"; 
  $conditions=query("SELECT * FROM conditions WHERE owner_id=?",$_SESSION['user_id']);

  redirect("conditions.php");
  }
  if($_POST['sub_save']=="حفظ")
  {
  
  $sql=query("INSERT INTO conditions (condition_txt ,owner_id ) VALUES (?,?)",$_POST['conditions'],$_SESSION['user_id']);
  $_SESSION['success_message'] = "تم الحفظ بنجاح"; 
  $conditions=query("SELECT * FROM conditions WHERE owner_id=?",$_SESSION['user_id']);

  redirect("conditions.php");
  }
  }
  $conditions=query("SELECT * FROM conditions WHERE owner_id=?",$_SESSION['user_id']);
  render("/settings/conditions.php",array("title"=>"ادارة شروط العقد","conditions"=>$conditions))
  ?>